<template>
  <div class="main">
    <div class="backImg"></div>
    <div class="login">
      <div class="title">
        <span>宿舍管理系统</span>
      </div>
      <div class="list">
        <el-input
          prefix-icon="el-icon-user"
          placeholder="请输入账号"
          v-model="dataFrom.username"
        ></el-input>
      </div>
      <div class="list">
        <el-input
          prefix-icon="el-icon-unlock"
          placeholder="请输入密码"
          show-password
          v-model="dataFrom.password"
        ></el-input>
      </div>
      <div class="links">
        <router-link to="/register">去注册</router-link>
        
        <router-link to="/changepassword">忘记密码</router-link>
      </div>
      <div class="btn">
        <button @click="login">登录</button>
      </div>
     
    </div>
  </div>
</template>
<script>
import axios from 'axios';
import {ElMessage} from 'element-plus'
export default {
  data() {
    return {
      dataFrom: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    login(){
      axios.get("http://localhost:8080/user/login?username=" + this.dataFrom.username +"&password=" + this.dataFrom.password).then(res =>{
        console.log("login",res.data)

          if(res.data == "登录成功"){
            ElMessage({
      message: res.data,
      type: 'success',
      duration: 2000
    })
            this.$router.push("home/main");
          }else{
            ElMessage({
      message: res.data,
      type: 'error',
      duration: 2000
    })
          }

      })
    },

    
   
  },
};
</script>
<style scoped>
.backImg {
  background: url("../img/back.jpg");
  background-size: 100% 100%;
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
}
.login {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid #ccc;
  background: #fff;
  width: 20%;
  padding: 20px 20px 25px 20px;
}
.login .title {
  text-align: center;
  padding-bottom: 5px;
}
.login .title span {
  font-size: 30px;
  color: #000;
}
 
.login .list {
  display: flex;
  align-items: center;
  padding: 8px 0;
}
.login .list input {
  border-radius: 3px;
  border: none;
  outline: none;
  color: #999;
  border: 1px solid #bdbdbd;
  font-size: 14px;
  line-height: 35px;
  padding: 0 10px;
  display: block;
  box-sizing: border-box;
  flex: 7;
}
 
.login .list .getCode span {
  font-size: 20px;
  background: #f5f7fa;
  color: #777;
  border-radius: 4px;
  line-height: 38px;
  border: 1px solid #ccc;
  display: inline-block;
  margin-left: 10px;
  width: 80px;
  text-align: center;
  user-select: none;
  cursor: pointer;
}
 
.btn {
  display: flex;
  justify-content: flex-end;
  padding-top: 5px;
}
.btn button {
  font-size: 13px;
  color: #fff;
  background: #46b5ff;
  outline: none;
  border: none;
  line-height: 35px;
  padding: 0 20px;
  display: inline-block;
  flex: 1;
  cursor: pointer;
}
.links {
  margin-top: 10px;
  text-align: center;
}

.links a {
  color: #46b5ff;
  text-decoration: none;
  margin: 0 10px;
}

.links a:hover {
  text-decoration: underline;
}
</style>
